#ifndef __RW_MUTEX_HPP
#define __RW_MUTEX_HPP

#include "lockable.hpp"
#include "mutex.hpp"
#include "condition.hpp"

namespace vpm 
{
	namespace utils
	{
		class RWMutex : public Lockable
		{
		public:
			RWMutex();
			~RWMutex();
			void lock_read();
			void lock_write();
			void lock();
			void unlock();
			unsigned int reader_count() const;
			unsigned int pending_writer_count() const;

		private:
			Mutex mMutex;
			Condition mReadCondition;
			Condition mPendingWriteCondition;
			unsigned int mReaderCount;
			bool mWriterHasLock;
			unsigned int mPendingWriterCount;
		};
	}
}
#endif 
